//package nbcp.filter
//
//import org.aspectj.lang.ProceedingJoinPoint
//import org.springframework.context.annotation.Configuration
//import org.springframework.core.Ordered
//import org.springframework.core.annotation.Order
//import org.springframework.web.filter.OncePerRequestFilter
//import nbcp.base.extend.AsString
//import nbcp.base.utils.SpringUtil
//import nbcp.db.mongo.entity.TraceLog
//import nbcp.db.mongo.mor
//import nbcp.web.MyHttpRequestWrapper
//import nbcp.web.MyHttpResponseWrapper
//import java.net.Inet4Address
//import java.nio.charset.Charset
//import javax.servlet.FilterChain
//import javax.servlet.annotation.WebFilter
//import javax.servlet.http.HttpServletRequest
//import javax.servlet.http.HttpServletResponse
//
//
//@Order(Ordered.HIGHEST_PRECEDENCE + 1)
//@Configuration
//@WebFilter(filterName = "traceFilter", urlPatterns = arrayOf("/*", "/**"))
//open class TraceFilter : OncePerRequestFilter() {
//    override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain) {
//        if (request.method == "HEAD" ||
//                request.method == "OPTIONS") {
//            return filterChain.doFilter(request, response)
//        }
//
//        procTrace(request, response);
//
//        return filterChain.doFilter(request, response)
//    }
//
//    private fun procTrace(request: HttpServletRequest, response: HttpServletResponse) {
//        var traceId = request.getAttribute(".trace.id.").AsString()
//        if (traceId.isEmpty()) return;
//
//        var ent = TraceLog();
//        ent.host = Inet4Address.getLocalHost().hostAddress + SpringUtil.context.environment.getProperty("local.server.port").AsString()
//        ent.url = request.requestURI + request.queryString.AsString().let {
//            if (it.isEmpty() == false) return@let "?" + it
//            return@let ""
//        }
//        ent.method = request.method
//        ent.traceId = traceId;
//        ent.header = request.headerNames.asSequence().map { it + ":" + request.getHeader(it) }.joinToString(",")
//
//        if (request is MyHttpRequestWrapper) {
//            ent.body = request.body.toString(utf8).trim()
//        }
//
//        mor.system.traceLog.insert(ent)
//    }
//}